package com.example.demo.mapper;

import com.example.demo.entity.User;
import com.example.demo.entity.USERO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zmh
 * @since 2021-06-30
 */
@Mapper
@Repository
public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT id,username,userpassword FROM user")
    List<User> findAll();

    @Select("SELECT id,username,userpassword,IS_VIP FROM user")
    List<USERO> findAllList();

    @Select("SELECT a.username,a.userpassword,a.id from user a where a.username = #{username} and a.userpassword= #{password}")
    List<User> chooseuser(String username, String password);

    @Select("INSERT into user(username,userpassword,IS_VIP) values (#{username},#{password},0)")
    Object adduser(String username,String password);

    @Select("SELECT a.username,a.userpassword,a.id from user a where a.username = #{username} ")
    Object selectuser(String username);

    @Select("SELECT a.IS_vip from user a where a.username = #{username} ")
    Object isvip(String username);
    
    @Select("SELECT username,address,phonenumber,Email,sex From userms where name = #{name}")
    List<User> finduserms(String name);

    @Select("UPDATE userms SET username=#{username},address=#{address},phonenumber=#{phonenumber},Email=#{Email},sex=#{sex} where  name = #{name}")
    Object addusers(String name,String username,String address,String phonenumber,String Email,String sex);

    @Select("SELECT username From user where openID=#{openID}")
    String findby_oid(String openID);

    @Select("INSERT into user(username,IS_VIP,openID) values (#{username},0,#{openID})")
    Object addhuaweiuser(String username,String openID);

    @Select("INSERT into userms(name,username,phonenumber,Email,sex) values (#{name},#{username},#{phonenumber},#{Email},#{sex})")
    Object addhuaweiuserms(String name,String username,String phonenumber,String Email,String sex);

    @Select("UPDATE user SET IS_VIP='1' where  username = #{username}")
    Object updatevip(String username);


}
